package Offer034;

/**
 * 外星语言是否排序
 * @author 23737
 * @time 2021.12.18
 */
public class Test {
    public static void main(String[] args) {

    }
}


class Solution {
    public boolean isAlienSorted(String[] words, String order) {
        int[] w = new int[26];
        for (int i = 25; i >= 0; i--) {
            w[order.charAt(25 - i) - 'a'] = i;
        }
        for (int i = 1; i < words.length; i++) {
            char[] pre = words[i - 1].toCharArray();
            char[] cur = words[i].toCharArray();
            for (int j = 0; j < pre.length; j++) {
                if (j > cur.length - 1) return false;
                if (w[pre[j] - 'a'] < w[cur[j] - 'a']) return false;
                if (w[pre[j] - 'a'] > w[cur[j] - 'a']) break;
            }
        }
        return true;
    }
}